package agent;

import server.AbstractStock;
import server.Product;
import server.ProductLot;
import server.exception.StockException;

/**
 * Diese Klasse hilft den einzelnen Product-Lots beim Transfer von einem Stock in den anderen.
 * (Stock->ShoppingCart bzw. ShoppingCart->Stock)
 * @author reto
 *
 */
public class ProductLotAgent {
	public static String SUCCESS="SUCCESS";
	private ProductLot productLot;
	private AbstractStock fromStock;
	private AbstractStock toStock;
	
	/**
	 * 
	 * @param productLot Welches ProductLot soll unterstützt werden
	 * @param fromStock In welchem Stock befindet es sich gerade
	 * @param toStock In welchen Stock soll es gegebenenfalls überführt werden
	 */
	public ProductLotAgent(final ProductLot productLot, final AbstractStock fromStock, final AbstractStock toStock) {
		super();
		this.productLot = productLot;
		this.fromStock = fromStock;
		this.toStock = toStock;
	}
	/**
	 * Convenience 
	 * @return gibt das ProductLot zurück.
	 */
	public ProductLot getProductLot() {
		return this.productLot;
	}	
	/**
	 * Convenience
	 * @see ProductLot#getProduct()
	 */
	public Product getProduct()
	{
		return this.getProductLot().getProduct();
	}	
	
	/**
	 * Convenience
	 * @see Product#getName()
	 */
	public String getProductName()
	{
		return this.getProduct().getName();
	}
	/**
	 * Convenience
	 * @see Product#getDescription()
	 */
	public String getProductDescription()
	{
		return this.getProduct().getDescription();
	}
	/**
	 * Convenience
	 * @see ProductLot#getAmount()
	 */
	public int getProductAmount()
	{
		return this.getProductLot().getAmount();
	}
	/**
	 * Convenience
	 * @see Product#getPrice()
	 */
	public double getProductPrice()
	{
		return this.getProduct().getPrice();
	}
	
	/**
	 * Diese Methode vollführt den Transfer eines Produktes dieses Lots.
	 * @return Status des Transfers:
	 * <ul>
	 * <li>SUCCESS</li>
	 * <li>NOT_IN_STOCK_EXCEPTION</li>
	 * <li>NOT_IN_CART_EXCEPTION</li>
	 * <li>OUT_OF_STOCK_EXCEPTION</li>
	 * </ul>
	 */
	public String swapProductAction()
	{
		String successString=ProductLotAgent.SUCCESS;
		try {
			this.toStock.addProduct(this.fromStock.removeProduct(this.productLot.getProduct().getName()));
		} catch (final StockException e) {
			successString=e.getMessage();
		}
		return successString;
	}
	
	
}
